<template>
  <div>
    <el-cascader
      :value="value"
      size="mini"
      :options="deptList"
      :props="{ label:'name',value:'id' }"
      @change="changeData"
    />
  </div>
</template>

<script>
import { getDepartmentApi } from '@/api/department'
import { transListToTreeData } from '@/utils'
export default {
  props: {
    value: {
      type: [Number, String],
      default: ''
    }
  },
  data() {
    return {
      deptList: []
    }
  },
  created() {
    this.getDeptList()
  },
  methods: {
    async getDeptList() {
      const res = await getDepartmentApi()
      this.deptList = transListToTreeData(res, 0)
    },
    changeData(val) {
      console.log(val)
      if (val.length === 0) return
      // 子父通信
      this.$emit('input', val[val.length - 1])
    }
  }
}
</script>

<style>

</style>
